const user = require("../../database/user")
const md5 = require("md5");

module.exports = async (req, res, next)=>{
  const {uId} = req.body;

  if(req.power !== 0){
    res.send({
      code:4,
      msg:"权限不够"
    })
    return;
  }

  if(!uId){
    res.send({
      code:3,
      msg:"缺少必传参数：uId"
    })
    return;
  }

  const data = await user.find( {uId} );

  await user.updateOne( {uId} , {password: md5(data[0].tel.slice(-6))});
  
  res.send({
    code: 1,
    msg:  "密码重置成功，新密码为手机号后6位"
  })
}